package com.bf.electroplating.controller;

import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.service.IRainfallSuspectedDischargeSyncService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 雨排口疑似偷排记录同步控制器
 *
 * @author system
 * @since 2025-01-11
 */
@Slf4j
@RestController
@RequestMapping("/api/rainfall-suspected-discharge-sync")
@Tag(name = "雨排口疑似偷排记录同步", description = "雨排口疑似偷排记录同步相关接口")
public class RainfallSuspectedDischargeSyncController {

    @Autowired
    private IRainfallSuspectedDischargeSyncService rainfallSuspectedDischargeSyncService;

    /**
     * 手动触发所有站点疑似偷排记录同步
     */
    @PostMapping("/sync-all")
    @Operation(summary = "同步所有站点疑似偷排记录", description = "手动触发同步所有站点的疑似偷排记录数据")
    public ResultVO<String> syncAllSuspectedDischargeData() {
        try {
            log.info("手动触发同步所有站点疑似偷排记录数据");
            rainfallSuspectedDischargeSyncService.syncAllSuspectedDischargeData();
            return ResultVO.ok("所有站点疑似偷排记录数据同步完成");
        } catch (Exception e) {
            log.error("手动同步所有站点疑似偷排记录数据失败", e);
            return ResultVO.fail("同步失败: " + e.getMessage());
        }
    }

    /**
     * 手动触发指定站点疑似偷排记录同步
     */
    @PostMapping("/sync-by-site/{siteId}")
    @Operation(summary = "同步指定站点疑似偷排记录", description = "手动触发同步指定站点的疑似偷排记录数据")
    public ResultVO<String> syncSuspectedDischargeDataBySite(
            @Parameter(description = "站点ID", required = true)
            @PathVariable("siteId") Integer siteId) {
        try {
            log.info("手动触发同步站点 {} 的疑似偷排记录数据", siteId);
            rainfallSuspectedDischargeSyncService.syncSuspectedDischargeDataBySiteId(siteId);
            return ResultVO.ok("站点 " + siteId + " 的疑似偷排记录数据同步完成");
        } catch (Exception e) {
            log.error("手动同步站点 {} 的疑似偷排记录数据失败", siteId, e);
            return ResultVO.fail("同步失败: " + e.getMessage());
        }
    }
}
